package com.hkts.beltweigher.master.controller;


import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.beltweigher.utils.CustomPageUtils;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.GetMapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.hkts.beltweigher.utils.Result;
import com.hkts.beltweigher.utils.ResultUtil;
import com.hkts.beltweigher.master.service.IRandomNumberSettingsService;
import com.hkts.beltweigher.master.entity.RandomNumberSettings;

/**
 * @author hml
 * @since 2024-04-18
 */
@RestController
@RequestMapping("/order/randomNumberSettings")
public class RandomNumberSettingsController {
    private final Logger logger = LoggerFactory.getLogger(RandomNumberSettingsController.class);

    @Autowired
    public IRandomNumberSettingsService iRandomNumberSettingsService;

    /**
     * 分页查询数据
     *
     * @param page                 分页信息
     * @param randomNumberSettings 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getRandomNumberSettingsPageList")
    public Result<Object> getHontUserList(Page<RandomNumberSettings> page, RandomNumberSettings randomNumberSettings) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iRandomNumberSettingsService.selectPage(page, randomNumberSettings)));
    }

    /**
     * 保存和修改公用的
     *
     * @param randomNumberSettings 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/randomNumberSettingsSave")
    public Result<Object> randomNumberSettingsSave(RandomNumberSettings randomNumberSettings) {
        iRandomNumberSettingsService.saveOrUpdate(randomNumberSettings);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/randomNumberSettingsGetById")
    public Result<Object> randomNumberSettingsGetById() {
        RandomNumberSettings byId = iRandomNumberSettingsService.getById(1);
        return ResultUtil.data(byId.getCoefficient());
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/randomNumberSettingsDelete")
    public Result<Object> hontUserDelete(String id) {
        iRandomNumberSettingsService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/randomNumberSettingsBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iRandomNumberSettingsService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/randomNumberSettingsUpdate")
    public Result<Object> randomNumberSettingsUpdate(Float coefficient) {
        Boolean aBoolean = iRandomNumberSettingsService.randomNumberSettingsUpdate(coefficient);
        if (aBoolean){
            return ResultUtil.success("修改成功");
        }else {
            return ResultUtil.error("修改失败");
        }
    }

}
